home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-26 | 2.9 KB | 116 lines | [TEXT/CWIE] |
- //
- // CCameraMaker.cp
- //
- // class CCameraMaker
- // A class that constructs a QuickDraw 3D View Angle Aspect camera.
- //
- // It's designed to make it easy to override camera placement
- // before calling Get() (or Make()) the first time.
- //
- // by James Jennings
- // November 26, 1995
- //
-
- #pragma once
-
- #include "CCameraMaker.h"
-
- CCameraMaker::CCameraMaker(const SDimension16 &frameSize)
- { // Fill in the structure default values.
- // These values come from Apple's "Start Here" demo.
- TQ3Point3D from = { 0.0, 0.0, 7.0 };
- TQ3Point3D to = { 0.0, 0.0, 0.0 };
- TQ3Vector3D up = { 0.0, 1.0, 0.0 };
-
- float fieldOfView = 1.0;
- float hither = 0.001;
- float yon = 1000;
-
- SetLocation(from);
- SetPointOfInterest(to);
- SetUpVector(up);
-
- mData.cameraData.range.hither= hither;
- mData.cameraData.range.yon = yon;
-
- mData.cameraData.viewPort.origin.x = -1.0;
- mData.cameraData.viewPort.origin.y = 1.0;
- mData.cameraData.viewPort.width = 2.0;
- mData.cameraData.viewPort.height = 2.0;
-
- mData.fov = fieldOfView;
- mData.aspectRatioXToY =
- (float) (frameSize.width) / (float) (frameSize.height);
- }
-
- void
- CCameraMaker::Make()
- {
- mObject = ::Q3ViewAngleAspectCamera_New(&mData);
- ThrowIfNil_(mObject);
- }
-
-
- void
- CCameraMaker::SetLocation(TQ3Point3D &from)
- {
- mData.cameraData.placement.cameraLocation = from;
- }
-
- void
- CCameraMaker::SetLocation(float x, float y, float z)
- {
- ::Q3Point3D_Set(&(mData.cameraData.placement.cameraLocation), x, y, z);
- }
-
- void
- CCameraMaker::SetPointOfInterest(TQ3Point3D &to)
- {
- mData.cameraData.placement.pointOfInterest = to;
- }
-
- void
- CCameraMaker::SetPointOfInterest(float x, float y, float z)
- {
- ::Q3Point3D_Set(&(mData.cameraData.placement.pointOfInterest), x, y, z);
- }
-
- void
- CCameraMaker::SetUpVector(TQ3Vector3D &up, Boolean orthogonalize)
- {
- mData.cameraData.placement.upVector = up;
- if (orthogonalize) Orthogonalize();
- }
-
- void
- CCameraMaker::SetUpVector(float x, float y, float z, Boolean orthogonalize)
- {
- ::Q3Vector3D_Set(&(mData.cameraData.placement.upVector), x, y, z);
- if (orthogonalize) Orthogonalize();
- }
-
- void
- CCameraMaker::Orthogonalize()
- { // make the upVector orthogonal to the line of sight vector
- // (Uses Gramm-Smit orthogonalization.)
-
- TQ3Vector3D lineOfSight; // v = vector from camera to point of interest
- ::Q3Point3D_Subtract(&(mData.cameraData.placement.pointOfInterest),
- &(mData.cameraData.placement.cameraLocation),
- &lineOfSight);
-
- TQ3Vector3D up = mData.cameraData.placement.upVector; // u = up
-
- ::Q3Vector3D_Normalize(&lineOfSight, &lineOfSight); // v = v/|v|
- ::Q3Vector3D_Normalize(&up, &up); // u = u/|u|
-
- float dot = ::Q3Vector3D_Dot(&lineOfSight, &up); // u.v = cos(angle between)
-
- ::Q3Vector3D_Scale(&lineOfSight, dot, &lineOfSight); //
- ::Q3Vector3D_Subtract(&up, &lineOfSight, &up); // u = u - v * (u.v)
- ThrowIf_(up.x==0 && up.y==0 && up.z==0); // u is now perpendicular to v
-
- mData.cameraData.placement.upVector = up;
- }
-
-